package com.ruoyi.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.base.domain.MaterialsParams;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.SjzMaterials;
import com.ruoyi.base.service.ISjzMaterialsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物品材料Controller
 * 
 * @author ruoyi
 * @date 2025-08-01
 */
@RestController
@RequestMapping("/base/materials")
public class SjzMaterialsController extends BaseController
{
    @Autowired
    private ISjzMaterialsService sjzMaterialsService;

    /**
     * 查询物品材料列表
     */
    @PreAuthorize("@ss.hasPermi('base:materials:list')")
    @GetMapping("/list")
    public TableDataInfo list(SjzMaterials sjzMaterials)
    {
        startPage();
        List<SjzMaterials> list = sjzMaterialsService.selectSjzMaterialsList(sjzMaterials);
        return getDataTable(list);
    }

    @PostMapping("/syn")
    public AjaxResult syn(@RequestBody MaterialsParams materialsParams){
        return sjzMaterialsService.synSjzMaterials(materialsParams);
    }

    /**
     * 导出物品材料列表
     */
    @PreAuthorize("@ss.hasPermi('base:materials:export')")
    @Log(title = "物品材料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SjzMaterials sjzMaterials)
    {
        List<SjzMaterials> list = sjzMaterialsService.selectSjzMaterialsList(sjzMaterials);
        ExcelUtil<SjzMaterials> util = new ExcelUtil<SjzMaterials>(SjzMaterials.class);
        util.exportExcel(response, list, "物品材料数据");
    }

    /**
     * 获取物品材料详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:materials:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sjzMaterialsService.selectSjzMaterialsById(id));
    }

    /**
     * 新增物品材料
     */
    @PreAuthorize("@ss.hasPermi('base:materials:add')")
    @Log(title = "物品材料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SjzMaterials sjzMaterials)
    {
        return toAjax(sjzMaterialsService.insertSjzMaterials(sjzMaterials));
    }

    /**
     * 修改物品材料
     */
    @PreAuthorize("@ss.hasPermi('base:materials:edit')")
    @Log(title = "物品材料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SjzMaterials sjzMaterials)
    {
        return toAjax(sjzMaterialsService.updateSjzMaterials(sjzMaterials));
    }

    /**
     * 删除物品材料
     */
    @PreAuthorize("@ss.hasPermi('base:materials:remove')")
    @Log(title = "物品材料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sjzMaterialsService.deleteSjzMaterialsByIds(ids));
    }
}
